#ifndef button_h
#define button_h

#include <stdbool.h>
#include "../system/events.h"
#include "../graphics/sprite.h"
#include "../graphics/text.h"
#include <SDL/SDL_ttf.h>


/**
 * @struct
 * @brief
 */
typedef struct EsdlButton EsdlButton;

struct EsdlButton {
    EsdlSprite* sprite; //!< @brief 
    SDL_Surface* backgroundSurface; //!< @brief 
    EsdlImage* backgroundImage; //!< @brief 
    char* text; //!< @brief 
    EsdlFont* textFont; //!< @brief 
    EsdlColor textColor; //!< @brief 
    void (*callback)(EsdlEvent*); //!< @brief 
};

/**
 * @brief Create a new button
 * @param char * text - The text of the button
 * @param unsigned int x - The abscissa of the top left corner
 * @param unsigned int y - The ordinate of the top left corner
 * @param unsigned int width - The width of the button
 * @param unsigned int height - The height of the button
 * @param void (*callback)(Event *) - The callback function executed when the button is clicked
 * @return Return a pointer on a Button structure
 */
EsdlButton* esdlCreateButton(const char* text, unsigned int x, unsigned int y, unsigned int width, unsigned int height, EsdlEventCallback callback);

/**
 * @brief Create a new button and load it render from an image file
 * @param char * path - The path of the button image. This image should be composed of three images of the save height, verticaly aligned. The first image should represent the button up, the second should represent the button down and the last image, the button when the mouse is over.
 * @param unsigned int x - The abscissa of the top left corner
 * @param unsigned int y - The ordinate of the top left corner
 * @param void (*callback)(Event *) - The callback function executed when the button is clicked
 * @return Return a pointer on a Button structure
 */
EsdlButton* esdlCreateButtonFromImageFile(const char* path, unsigned int x, unsigned int y, EsdlEventCallback callback);

/*
 * @brief Create a new button and load it render from an image ressource
 * @param Image * image - The image ressource structure. This image should be composed of three images of the save height, verticaly aligned. The first image should represent the button up, the second should represent the button down and the last image, the button when the mouse is over.
 * @param unsigned int x - The abscissa of the top left corner
 * @param unsigned int y - The ordinate of the top left corner
 * @param void (*callback)(Event *) - The callback function executed when the button is clicked
 * @return Return a pointer on a Button structure
 */
EsdlButton* esdlCreateButtonFromImage(EsdlImage * image, unsigned int x, unsigned int y, EsdlEventCallback callback);

/**
 * @brief This function delete a button and free the memory
 * @param Button * button - The button to delete
 */
void esdlDeleteButton(EsdlButton* button);

/**
 * @brief This function change the button text
 * @param Button * button
 * @param char * text
 */
void esdlSetButtonText(EsdlButton* button, const char* text);

/**
 * @brief Change the text font
 * @param Button * button
 * @param TTF_Font *
 * @see Function loadTextFont()
 */
void esdlSetButtonTextFont(EsdlButton* button, EsdlFont* font);

/**
 * @brief Change the text color
 * @param Button * button
 * @param Color color
 * @see Function newColor()
 */
void esdlSetButtonTextColor(EsdlButton* button, EsdlColor color);

/**
 * @brief Change the background color of the buttonUp image
 * @param Button * button
 * @param Color color
 * @see Function newColor()
 */
void esdlSetBackgroundColorUp(EsdlButton* button, EsdlColor color);

/**
 * @briefChange the background color of the buttonDown image
 * @param Button * button
 * @param Color color
 * @see Function newColor()
 */
void esdlSetBackgroundColorDown(EsdlButton* button, EsdlColor color);

/**
 * @briefChange the background color of the buttonHover image
 * @param Button * button
 * @param Color color
 * @see Function newColor()
 */
void esdlSetBackgroundColorHover(EsdlButton* button, EsdlColor color);

/**
 * @param Button * button - 
 * @return Return a pointer on the button sprite 
 */
EsdlSprite* esdlGetSpriteFromButton(EsdlButton* button);

/**
 * @brief Show the button
 * @param EsdlButton * button
 */
void esdlShowButton(EsdlButton* button);

/**
 * @brief Hide the button
 * @param EsdlButton * button
 */
void esdlHideButton(EsdlButton* button);

/**
 * @brief Hide the button if it's shown. Show it if it's hided
 * @param EsdlButton * button
 */
void esdlToggleButtonVisibility(EsdlButton* button);

#endif
